﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Tayninh2011
{
    public sealed partial class FrmAddSdeData : RootForm
    {
        private static readonly FrmAddSdeData frmAddSdeData = new FrmAddSdeData();
        private ITnMapController mapController = new TnMapController();
        private FrmCash frmCash= FrmCash.CallMe;
        private FrmAddSdeData()
        {
            InitializeComponent();
        }

        public static FrmAddSdeData CallMe
        {
            get { return frmAddSdeData; }
        }

        public new void Show()
        {
            if (isShown)
            {
                base.Show();
            }
            else
            {
                base.Show();
                
                isShown = true;
            }
        }
        private static bool isShown = false;

        static FrmAddSdeData()
        {

            frmAddSdeData.FormClosing += new FormClosingEventHandler(frm_FormClosing);

        }
        private static void frm_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            isShown = false;
            frmAddSdeData.Hide();
        }

        private void FrmAddSdeData_Load(object sender, EventArgs e)
        {
            ITnQueryFilter queryFilter = new TnQueryFilterBuilder()
                .SqlConnection(RootForm._arrUserInfo)
                .Table("sde.SDE_layers")
                .Fields("table_name")
                .BuildQuery();
            queryFilter.Excute();
            SqlDataReader reader = queryFilter.GetResultCursor();
            while (reader.Read())
            {
                lbxLayers.Items.Add(reader.GetString(0));
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            int len = lbxLayers.SelectedItems.Count;
            string[] layers = new string[len];
            for(int i=0;i<len;i++)
            {
                layers[i]=lbxLayers.SelectedItems[i].ToString();
            }
            frmCash.AddLayer(layers);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
